from flask_restful import Resource
from flask import request, session
from database import Database

# 创建数据库连接


# Mock user database
class GetBook(Resource):

    def get(self):
        db = Database()
        data = request.get_json()
        bookId = data['bookId']

        book = db.execute_query("select * from book where bookId=%s", (bookId,))
        if book:
            book_json = {
                "bookId": book[0],
                "categoryId": book[1],
                "imageUrl": book[2],
                "title": book[3],
                "description": book[4],
                "stackId": book[5],
                "ownerId": book[6],
                "condition": book[7],
                "fee": str(book[8]),
                "price": str(book[9]),
                "author": book[10],
                "status": book[11]
            }
            return {"book": book_json}, 200
        else:
            return {"message": "server internal error"}, 404
